using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DAL;
using BLL;
using DTO;

namespace WellmeadowsHospital
{
    public partial class frmAddOutPatients : DevExpress.XtraEditors.XtraUserControl
    {
        AppointmentBLL appointmentBLL = new AppointmentBLL();
        WardBLL wardBLL = new WardBLL();
        PatientBLL patientBLL = new PatientBLL();
        ListWaitBLL listwaitBLL = new ListWaitBLL();
        OutPatientsBLL outpatientsBLL = new OutPatientsBLL();
        StaffBLL staffBLL = new StaffBLL();

        public frmAddOutPatients()
        {
            InitializeComponent();
            gridControl4.DataSource = staffBLL.SelectAll();
            gridControl5.DataSource = appointmentBLL.SelectAll();
        }

        private void textEdit89_KeyPress(object sender, KeyPressEventArgs e)
        {
            string key = textEdit89.Text;
            if (!key.Equals(""))
            {
                gridControl5.DataSource = appointmentBLL.SearchwithStafforPatient(key);
            }
            else
            {
                gridControl5.DataSource = appointmentBLL.SelectAll();
            }
        }

        private void gridView14_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            try
            {
                string mapa = gridView14.GetRowCellValue(gridView14.GetSelectedRows()[0], gcolPatientIDinAddAppointClinicH).ToString();
                textEdit93.Text = gridView14.GetRowCellValue(gridView14.GetSelectedRows()[0], gcolAppointIDinAddAppointClinicH).ToString();
                gridControl3.DataSource = patientBLL.Search(mapa);
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }

        private void gridView13_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            try
            {
                textEdit91.Text = gridView13.GetRowCellValue(gridView13.GetSelectedRows()[0], gridColumn85).ToString();
       
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }

        private void simpleButton15_Click(object sender, EventArgs e)
        {
            try
            {
                string appointid = textEdit93.Text;
                OutPatientsDTO nhap = new OutPatientsDTO();
                nhap.AppointmentID = appointid;
                nhap.StaffID = textEdit91.Text;
                nhap.ClinicNo = textEdit94.Text;
                nhap.Date = dateEdit14.DateTime;
                nhap.Time = timeEdit3.Time.ToString();
                string patientid = appointmentBLL.GetPatientID(appointid);
                if (outpatientsBLL.Insert(nhap).Equals("success") && patientBLL.UpdateTo_OutPatient(patientid).Equals("success") && appointmentBLL.UpdateTo_OutPatient(appointid).Equals("success"))
                {
                    MessageBox.Show("Insert OutPatients success!");
                }
                else
                {
                    MessageBox.Show(outpatientsBLL.Insert(nhap));
                }
            }
            catch (Exception eee)
            {
                MessageBox.Show(eee.Message);
            }
        }
    }
}
